﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Controls;
namespace WPFExcelReport
{
    public partial class TPWS02VAR
    {
        public TPWS02VAR()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VWASTAMM();
            this.DataContext = MV;
            InitializeComponent();
            IsEdit = false;
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwWS = dwMaster;
            if (dwMaster == null)
            {
                KEY = "";
            }
            else
            {
                KEY = TMV.WAART + TMV.WAVAR;
            }
        }

        public override void OnEXAUFChg(string vlaue)
        {
            TBMain.Clear();
            if (!IsCanLoad)
                return;
            if (vlaue == "")
                return;
            dwData = TBMain.NewRow();
            dwData["WAMANDANT"] = app.Mandant;
            dwData["WADART"] = vlaue.Substring(0, 20);
            dwData["WADVAR"] = "  ";
            SResult = TMV.QWSDART(dwData);
            MergeData(SResult, true);
            base.OnEXAUFChg(vlaue);
        }
        public override void NewCommand(object sender, RoutedEventArgs e)
        { 
            DataRow dwDWS = null; 
            dwData = TBMain.NewRow();
            dwData["WAMANDANT"] = app.Mandant;
            dwData["WADART"] = TMV.WAART;
            dwData["WADVAR"] = "  ";
            SResult = TMV.QWSDART(dwData);
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwDWS = SResult.Tables[0].Copy().Rows[0];
            }
            if (dwDWS != null)
            {
                PM["dwDWS"] = dwDWS;
            }
            PM["ART"] = TMV.WAART;
            PM["VAR"] = VAR;
            PM["BEZ"] = DES;
            PM["PROGRP"] = PRODGRP;
            PM["ARTGRP"] = ARTGRP;
            PM["FDDIM"] = DENUM;
            PM["WABIND"] = "0.00".PadRight(12) + "M  ";
            
            TMV.NEWWS(PM);
            vwMaster.View.MoveCurrentToFirst(); 
        }
    }
}
